
use "/Users/mbfehrs/Desktop/Matt's Hard Drive /Papers/Never Fear to Negotiate/Peaceful Rallies + Baum Data.dta"

gen ln_total_app = ln(total_app)
gen ln_rep_app = ln(rep_app)
gen ln_dem_app = ln(dem_app)
gen ln_ind_app = ln(ind_app)
gen ln_grade_ap = ln(grade_ap)
gen ln_highschool_app = ln(highschool_app)
gen ln_college_app = ln(college_app)

gen total_app_ch = total_app-total_app[_n-1]
gen dem_app_ch = dem_app-dem_app[_n-1]
gen rep_app_ch = rep_app-rep_app[_n-1]
gen ind_app_ch = ind_app-ind_app[_n-1]
gen grade_app_ch = grade_ap-grade_ap[_n-1]
gen highschool_app_ch = highschool_app-highschool_app[_n-1]
gen college_app_ch = college_app-college_app[_n-1]

gen ln_total_app_ch = ln_total_app-ln_total_app[_n-1]
gen ln_rep_app_ch = ln_rep_app-ln_rep_app[_n-1]
gen ln_dem_app_ch = ln_dem_app-ln_dem_app[_n-1]
gen ln_ind_app_ch = ln_ind_app-ln_ind_app[_n-1]
gen ln_grade_app_ch = ln_grade_ap-ln_grade_ap[_n-1]
gen ln_highschool_app_ch = ln_highschool_app-ln_highschool_app[_n-1]
gen ln_college_app_ch = ln_college_app-ln_college_app[_n-1]

*AR1*
gen total_app_lag = ln_total_app[_n-1]
gen rep_app_lag = ln_rep_app[_n-1]
gen dem_app_lag = ln_dem_app[_n-1]
gen ind_app_lag = ln_ind_app[_n-1]
gen grade_app_lag = ln_grade_app[_n-1]
gen highschool_app_lag = ln_highschool_app[_n-1]
gen college_app_lag = ln_college_app[_n-1]

*AR2*
gen total_app_lag2 = ln_total_app[_n-2]
gen rep_app_lag2 = ln_rep_app[_n-2]
gen dem_app_lag2 = ln_dem_app[_n-2]
gen ind_app_lag2 = ln_ind_app[_n-2]
gen grade_app_lag2 = ln_grade_app[_n-2]
gen highschool_app_lag2 = ln_highschool_app[_n-2]
gen college_app_lag2 = ln_college_app[_n-2]

*AR3*
gen total_app_lag3 = ln_total_app[_n-3]
gen rep_app_lag3 = ln_rep_app[_n-3]
gen dem_app_lag3 = ln_dem_app[_n-3]
gen ind_app_lag3 = ln_ind_app[_n-3]
gen grade_app_lag3 = ln_grade_app[_n-3]
gen highschool_app_lag3 = ln_highschool_app[_n-3]
gen college_app_lag3 = ln_college_app[_n-3]

*AR4*
gen total_app_lag4 = ln_total_app[_n-4]
gen rep_app_lag4 = ln_rep_app[_n-4]
gen dem_app_lag4 = ln_dem_app[_n-4]
gen ind_app_lag4 = ln_ind_app[_n-4]
gen grade_app_lag4 = ln_grade_app[_n-4]
gen highschool_app_lag4 = ln_highschool_app[_n-4]
gen college_app_lag4 = ln_college_app[_n-4]

gen peace_rally = 1 if rally_num !=.
recode peace_rally .=0
gen republican_peace = 1 if republican_president==1 & peace_rally==1
recode republican_peace .=0

recode arms_control .=0
recode limit_force .=0
recode trade .=0
recode china_normal .=0
recode global_order .=0

gen mil_talks = 1 if arms_control==1 | limit_force==1 | global_order==1
recode mil_talks .=0
gen china_talks = 1 if china_normal==1 | china_open==1
recode china_talks .=0


gen heads_mtg = 1 if level_of_meeting==2
recode heads_mtg .=0

gen heads_or_sec = 1 if level_of_meeting==2
recode heads_or_sec .=2 if level_of_meeting==1

gen front_page_event = 1 if front_page==1 & peace_rally==1
recode front_page_event .=0 if front_page==0 & peace_rally==1

gen multi = 1 if bi_multi==2
recode multi .=0
gen bi = 1 if bi_multi==1
recode bi .=0

gen bi_agree = bi*agreement
recode bi_agree .=0

gen bi_div = bi*divgov
recode bi_div .=0

gen force_lg = forceyr[_n-1] if newadmin !=1
recode force_lg .=0

gen bi_force = 1 if bi==1 & force_lg !=0
recode bi_force .=0

gen bi_rally = bi*rallies_in_term
recode bi_rally .=0

gen bi_yr = bi*yrsinoffice
recode bi_yr .=0

gen republican_bi = 1 if republican_president==1 & bi==1
recode republican_bi .=0

gen dem_bi = 1 if republican_president==0 & bi==1
recode dem_bi .=0

gen sovietforce = 1 if sovietmidlevel==4
recode sovietforce .=0

gen sec_meet =1 if global_order==1 | limit_force==1
recode sec_meet .=0

recode agreement .=0
recode level_of_meeting .=0
recode treaty .=0
recode sovietmid .=0
recode sovietmidlevel .=0
recode sovietusmid .=0
recode us_soviet_icb .=0
recode us_icb .=0
recode conflict_meeting .=0

gen global_bi = 1 if global_order==1 & bi==1
recode global_bi .=0
gen trade_bi = 1 if trade==1 & bi==1
recode trade_bi .=0
gen limit_bi = 1 if limit_force==1 & bi==1
recode limit_bi .=0
gen arms_bi = 1 if arms_control==1 & bi==1
recode arms_bi .=0

gen no_pub =1 if front_page==0 & peace_rally==1
recode no_pub .=0

gen date_new = date(date, "MD19Y")
format date_new %tdDDmonCCYY

*Extract Year*
gen year = yofd(date_new)

recode front_page .=0

recode future_meetings .=0

gen rally_year = year*bi

gen soviet_mtg = 1 if country_num==1
recode soviet_mtg .=0

sum total_app_ch if peace_rally==1
sum total_app_ch if peace_rally !=1

sum total_app_ch if bi==1
sum total_app_ch if bi !=1

sum rep_app_ch if peace_rally==1 & level_of_meeting==2 & republican_president==1
sum rep_app_ch if peace_rally==1 & level_of_meeting==2 & republican_president==0

sum grade_app_ch if peace_rally==1 & level_of_meeting==2
sum college_app_ch if peace_rally==1 & level_of_meeting==2 & republican_president==1
sum college_app_ch if peace_rally==1 & level_of_meeting==2 & republican_president==0

*Gen labels*
label variable ln_total_app_ch "Change in Approval Rating"
label variable bi "Bilateral Meeting" 
label variable rally "Military Rally"
label variable agreement "Agreement"
label variable front_page "Front Page"
label variable divgov "Divided Government"
label variable inflation "Inflation"
label variable unemploy "Unemployment"
label variable pres_elec_yr "Presidential Election Year"
label variable newadmin "Honeymoon"
label variable fprobs "Foreign Policy Salience"
label variable lameduck "Second Term"
label variable total_app_lag "Previous Popularity"
label variable heads_mtg "Heads of State Meeting"
label variable ln_rep_app_ch "Change in Approval Rating - Republican Voters"
label variable rep_app_lag "Previous Popularity - Republican Voters"
label variable ln_dem_app_ch "Change in Approval Rating - Democratic Voters"
label variable dem_app_lag "Previous Popularity - Democratic Voters"
label variable future_meetings "Future Meetings Planned"
label variable sovietforce "Soviet Use of Force"
label variable sovietmid "Soviet MID"
label variable sovietusmid "Soviet-US MID"
label variable us_soviet_icb "Soviet-US ICB"
label variable us_icb "US Crisis"
label variable republican_president "Republican President"
label variable global_bi "Global Security Management"
label variable trade_bi "Trade"
label variable limit_bi "Bilateral Security Management"
label variable arms_bi "Arms Control"

*Revised regressions - different controls*
*Need to have outregs saved to correct location*
cd "/Users/mbfehrs/Desktop/Matt's Hard Drive /Papers/Never Fear to Negotiate/"

*Generate summary stats - Table 1*
sum total_app_ch bi global_bi trade_bi limit_bi divgov pres_elec_yr newadmin lameduck inflation unemploy us_icb sovietusmid total_app_lag rep_app_lag dem_app_lag if country_num !=2 & watergate !=1 & clinton !=1

*T-test for heads of state meetings versus secretaries of state - not significant difference*
ttest total_app_ch, by(heads_or_sec)

//*Main Regression*//
*Table 2 - looks at all meetings*
bootstrap, reps(100): reg ln_total_app_ch bi divgov pres_elec_yr newadmin lameduck inflation unemploy us_icb sovietusmid total_app_lag if country_num !=2 & watergate !=1 & clinton !=1, robust
outreg using Table2, var starlevels(10 5 1) sigsymbols(+,*,**) ct("", Baseline) replace

bootstrap, reps(100): reg ln_total_app_ch global_bi trade_bi limit_bi divgov pres_elec_yr newadmin lameduck inflation unemploy us_icb sovietusmid total_app_lag if country_num !=2 & watergate !=1 & clinton !=1, robust
outreg using Table2, var starlevels(10 5 1) sigsymbols(+,*,**) ct("", All Presidents) merge

*Republican Presidents*
bootstrap, reps(100): reg ln_total_app_ch global_bi trade_bi limit_bi divgov pres_elec_yr newadmin lameduck inflation unemploy  us_icb sovietusmid total_app_lag if country_num !=2 & watergate !=1 & clinton !=1 & republican_president==1, robust
outreg using Table2, var starlevels(10 5 1) sigsymbols(+,*,**) ct("", Republican Presidents) merge

*Democratic Presidents - must remove global_order and trade because those were not the focus of any meetings during Dem terms*
bootstrap, reps(100): reg ln_total_app_ch arms_bi limit_bi pres_elec_yr newadmin inflation unemploy  us_icb sovietusmid total_app_lag if country_num !=2 & watergate !=1 & clinton !=1 & republican_president==0, robust
outreg using Table2, var starlevels(10 5 1) sigsymbols(+,*,**) ct("", Democratic Presidents) merge

//*Partisan Regressions*//
*Table 3 - Democratic voters*
bootstrap, reps(100): reg ln_dem_app_ch global_bi trade_bi limit_bi divgov pres_elec_yr newadmin lameduck inflation unemploy us_icb sovietusmid  dem_app_lag if clinton !=1 & country_num !=2 & watergate !=1, robust
outreg using Table3, var starlevels(10 5 1) sigsymbols(+,*,**) title(Democratic Voters) ct("", All Presidents) replace

bootstrap, reps(100): reg ln_dem_app_ch global_bi trade_bi limit_bi divgov pres_elec_yr newadmin lameduck inflation unemploy us_icb sovietusmid dem_app_lag if watergate !=1 & country_num !=2 & clinton !=1 & republican_president==1, robust
outreg using Table3, var starlevels(10 5 1) sigsymbols(+,*,**) title(Democratic Voters) ct("", Republican Presidents) merge

bootstrap, reps(100): reg ln_dem_app_ch arms_bi limit_bi pres_elec_yr newadmin inflation unemploy  us_icb sovietusmid dem_app_lag if watergate !=1 & country_num !=2 & clinton !=1 & republican_president==0, robust
outreg using Table3, var starlevels(10 5 1) sigsymbols(+,*,**) title(Democratic Voters) ct("", Democratic Presidents) merge

*Table 4 - Republican voters*
bootstrap, reps(100): reg ln_rep_app_ch global_bi trade_bi limit_bi divgov pres_elec_yr newadmin lameduck inflation unemploy us_icb sovietusmid rep_app_lag if country_num !=2 & clinton !=1, robust
outreg using Table4, var starlevels(10 5 1) sigsymbols(+,*,**) title(Republican Voters) ct("", All Presidents) replace

bootstrap, reps(100): reg ln_rep_app_ch global_bi trade_bi limit_bi divgov pres_elec_yr newadmin lameduck inflation unemploy us_icb sovietusmid rep_app_lag if watergate !=1 & country_num !=2 & clinton !=1 & republican_president==1, robust
outreg using Table4, var starlevels(10 5 1) sigsymbols(+,*,**) title(Republican Voters) ct("", Republican Presidents) merge

bootstrap, reps(100): reg ln_rep_app_ch arms_bi limit_bi pres_elec_yr newadmin inflation unemploy us_icb sovietusmid rep_app_lag if watergate !=1 & country_num !=2 & clinton !=1 & republican_president==0, robust
outreg using Table4, var starlevels(10 5 1) sigsymbols(+,*,**) title(Republican Voters) ct("", Democratic Presidents) merge

//*Table 5 - Just looking at meetings themselves - ie only the results following meetings*//
bootstrap, reps(100): reg ln_total_app_ch global_bi trade_bi limit_bi divgov inflation unemploy pres_elec_yr newadmin us_icb sovietusmid total_app_lag if watergate !=1 & clinton !=1 & peace_rally==1 & country_num !=2, robust
outreg using Table5, var starlevels(10 5 1) sigsymbols(+,*,**) title(Only Meetings)  ct("", All Voters) replace

bootstrap, reps(100): reg ln_dem_app_ch global_bi trade_bi limit_bi divgov inflation unemploy pres_elec_yr newadmin us_icb sovietusmid dem_app_lag if watergate !=1 & clinton !=1 & peace_rally==1 & country_num !=2, robust
outreg using Table5, var starlevels(10 5 1) sigsymbols(+,*,**) title(Only Meetings) ct("", Democratic Voters) merge

bootstrap, reps(100): reg ln_rep_app_ch global_bi trade_bi limit_bi divgov inflation unemploy pres_elec_yr newadmin us_icb sovietusmid rep_app_lag if clinton !=1 & peace_rally==1 & country_num !=2, robust
outreg using Table5, var starlevels(10 5 1) sigsymbols(+,*,**) title(Only Meetings) ct("", Republican Voters) merge

